import java.util.*;

public class Practice2 {
    //https://www.nowcoder.com/questionTerminal/b2b816e20e8343b49abbaf493886ce26
    //还未写出, 先放着
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] ss1 = sc.next().toCharArray();
        char[] ss2 = sc.next().toCharArray();
        int[] hash = new int[26];
        for (int i = 0; i < ss1.length; i++) {
            hash[ss1[i] - 'a']--;
        }
        int left = 0;
        int count = 0;
        int index = 0;
        int maxCount = 0;
        for (int right = 0; right < ss2.length;right++) {
            int dex = ss2[right] - 'a';
            if(hash[dex]++ < 0){
                count++;
            }
            if(right - left + 1 == ss1.length){
                if(maxCount <= count){
                    index = left;
                    maxCount = count;
                }
                if(hash[left]-- <= 0 ){
                    count--;
                }
            }
        }
        System.out.println(ss2.length - index - count);
    }
}
